package com.ruoyi.project.jiaqin.supplycomment.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.supplycomment.domain.SupplyComment;
import com.ruoyi.project.jiaqin.supplycomment.service.ISupplyCommentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 供应评论Controller
 * 
 * @author admin
 * @date 2021-02-22
 */
@Controller
@RequestMapping("/jiaqin/supplycomment")
public class SupplyCommentController extends BaseController
{
    private String prefix = "jiaqin/supplycomment";

    @Autowired
    private ISupplyCommentService supplyCommentService;

    @RequiresPermissions("jiaqin:supplycomment:view")
    @GetMapping()
    public String supplycomment()
    {
        return prefix + "/supplycomment";
    }

    /**
     * 查询供应评论列表
     */
    @RequiresPermissions("jiaqin:supplycomment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SupplyComment supplyComment)
    {
        startPage();
        List<SupplyComment> list = supplyCommentService.selectSupplyCommentList(supplyComment);
        return getDataTable(list);
    }

    /**
     * 导出供应评论列表
     */
    @RequiresPermissions("jiaqin:supplycomment:export")
    @Log(title = "供应评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SupplyComment supplyComment)
    {
        List<SupplyComment> list = supplyCommentService.selectSupplyCommentList(supplyComment);
        ExcelUtil<SupplyComment> util = new ExcelUtil<SupplyComment>(SupplyComment.class);
        return util.exportExcel(list, "supplycomment");
    }

    /**
     * 新增供应评论
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应评论
     */
    @RequiresPermissions("jiaqin:supplycomment:add")
    @Log(title = "供应评论", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SupplyComment supplyComment)
    {
        return toAjax(supplyCommentService.insertSupplyComment(supplyComment));
    }

    /**
     * 修改供应评论
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        SupplyComment supplyComment = supplyCommentService.selectSupplyCommentById(id);
        mmap.put("supplyComment", supplyComment);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应评论
     */
    @RequiresPermissions("jiaqin:supplycomment:edit")
    @Log(title = "供应评论", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SupplyComment supplyComment)
    {
        return toAjax(supplyCommentService.updateSupplyComment(supplyComment));
    }

    /**
     * 删除供应评论
     */
    @RequiresPermissions("jiaqin:supplycomment:remove")
    @Log(title = "供应评论", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(supplyCommentService.deleteSupplyCommentByIds(ids));
    }
}
